/**
* Copyright (C) qzgf, 2012
*
* License        :Apache License 2.0
* Project        :qzgfjava
* Package        :com.qzgf.application.appsystem.main.action
* File	         :main.java
* Written by     :fjfdszj
* Created Date   :May 21, 2012
* Purpose        :功能描述

======================================

* Modifyer by    :fjfdszj
* Update Date    :May 21, 2012
* Purpose        :描述

*/
package com.qzgf.application.appsystem.main.action;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.ActionContext;
import com.qzgf.application.BaseAction;
import com.qzgf.application.appsystem.main.domain.MainFacade;
import com.qzgf.core.common.AjaxResult;
import com.qzgf.core.common.Constant;
import com.qzgf.core.common.Util;

/**
 * Purpose      : 说明
 *
 * @author fjfdszj
 * @see     DepartmentAction.java
 *
 */
public class MainAction extends BaseAction{
	/**
	 * Purpose      : 说明
	 */
	
	private MainFacade mainFacade;
	
    private static Logger logger = Logger.getLogger(MainAction.class) ;
	
	
	/**
	 * 
	 * Purpose      : 框架左菜单
	 * @return
	 */
	public String GetTreeJson() {
		logger.info("框架树型菜单显示！");
		List menuList = mainFacade.findMenu("0");
		StringBuffer menustr = new StringBuffer();
		menustr.append("[");
		menustr.append(mainFacade.GetTree(menuList,"0"));
		menustr.append("]");
		json = menustr.toString();
		return viewjson;
	}
	
	/**
	 * 
	 * Purpose      : 系统按钮
	 * @return
	 */
	public String GetButtonJson() {
		List buttonList = mainFacade.findSysButton("0");
		AjaxResult ar=AjaxResult.Success(buttonList);
		json = ar.toString();
		return viewjson;
	}

	
	/**
	 * 
	 * Purpose      : 用户信息验证
	 * @return
	 */
	public String Login(){
		boolean result=false;
		//1.验证码
		String authcode=ActionContext.getContext().getSession().get(Constant.VERIFY_SESSION_NAME).toString();
		if(authcode.equals(search.get("authcode").toString())){
			//2.取得用户信息
			HashMap hs=mainFacade.findUserbyName(search.get("username").toString());
			//3.密码
			if(hs!=null){
				String md5pwd=Util.hash(search.get("password").toString());
				if((md5pwd).equalsIgnoreCase(hs.get("password").toString())){
					result=true;
				}
			}
		}
		
		java.lang.StringBuffer sb = new StringBuffer();
		sb.append(result);
		json = sb.toString();
		return viewjson;
	}
	
	/**
	 * 
	 * Purpose      : 框架页面
	 * @return
	 */
	public String Index(){
		return "viewmain";
	}
	
	/**
	 * 
	 * Purpose      : 登录页面
	 * @return
	 */
	public String Viewlogin(){
		return "viewlogin";
	}
	//=======================================================常量设置=================================
	//=================================================================================================
	/**
	 * Purpose      : 说明
	 * @return the mainFacade
	 */
	public MainFacade getMainFacade() {
		return mainFacade;
	}

	/**
	 * Purpose      : 说明
	 * @param mainFacade the mainFacade to set
	 */
	
	public void setMainFacade(MainFacade mainFacade) {
		this.mainFacade = mainFacade;
	}
}
